local assets = {

}


local function fn()
    local inst = CreateEntity()
    
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddSoundEmitter()
    inst.entity:AddDynamicShadow()
    inst.entity:AddMiniMapEntity()
    inst.entity:AddLight()
    inst.entity:AddLightWatcher()
    inst.entity:AddNetwork()

    inst.Transform:SetFourFaced()

    inst.AnimState:SetBank("wilson")
    inst.AnimState:SetBuild("wilson")

    inst.AnimState:PlayAnimation("idle")

    inst.AnimState:Hide("ARM_carry")
    inst.AnimState:Hide("HAT")
    inst.AnimState:Hide("HAIR_HAT")
    inst.AnimState:Show("HAIR_NOHAT")
    inst.AnimState:Show("HAIR")
    inst.AnimState:Show("HEAD")
    inst.AnimState:Hide("HEAD_HAT")

    inst.AnimState:OverrideSymbol("fx_wipe", "wilson_fx", "fx_wipe")
    inst.AnimState:OverrideSymbol("fx_liquid", "wilson_fx", "fx_liquid")
    inst.AnimState:OverrideSymbol("shadow_hands", "shadow_hands", "shadow_hands")
    inst.AnimState:OverrideSymbol("snap_fx", "player_actions_fishing_ocean_new", "snap_fx")

    --Additional effects symbols for hit_darkness animation
    inst.AnimState:AddOverrideBuild("player_hit_darkness")
    inst.AnimState:AddOverrideBuild("player_receive_gift")
    inst.AnimState:AddOverrideBuild("player_actions_uniqueitem")
    inst.AnimState:AddOverrideBuild("player_wrap_bundle")
    inst.AnimState:AddOverrideBuild("player_lunge")
    inst.AnimState:AddOverrideBuild("player_attack_leap")
    inst.AnimState:AddOverrideBuild("player_superjump")
    inst.AnimState:AddOverrideBuild("player_multithrust")
    inst.AnimState:AddOverrideBuild("player_parryblock")
    inst.AnimState:AddOverrideBuild("player_emote_extra")
    inst.AnimState:AddOverrideBuild("player_boat_plank")
    inst.AnimState:AddOverrideBuild("player_boat_net")
    inst.AnimState:AddOverrideBuild("player_boat_sink")
    inst.AnimState:AddOverrideBuild("player_oar")

    inst.AnimState:AddOverrideBuild("player_actions_fishing_ocean_new")
    inst.AnimState:AddOverrideBuild("player_actions_farming")
    inst.AnimState:AddOverrideBuild("player_actions_cowbell") 


    inst.DynamicShadow:SetSize(1.3, .6)

    -- inst.Light:SetIntensity(.8)
    -- inst.Light:SetRadius(.5)
    -- inst.Light:SetFalloff(.65)
    -- inst.Light:SetColour(255 / 255, 255 / 255, 236 / 255)
    -- inst.Light:Enable(false)

    inst.Light:SetIntensity(.8)
    inst.Light:SetRadius(1.3)
    inst.Light:SetFalloff(.65)
    inst.Light:SetColour(255 / 255, 255 / 255, 236 / 255)
    inst.Light:Enable(false)

    inst.LightWatcher:SetLightThresh(.075)
    inst.LightWatcher:SetMinLightThresh(0.61) --for sanity.
    inst.LightWatcher:SetDarkThresh(.05)

    MakeCharacterPhysics(inst, 75, .5)

    inst:AddTag("NPC")
    inst:AddTag("NPC_EVENT")
    -- inst:AddTag("npc_ghost")

    ---------------------------------------------------------------------------------------------
    -- talker 组件
    inst:AddComponent("talker")
    local function GetTalkerOffset(inst)
        local TALLER_TALKER_OFFSET = Vector3(0, -700, 0)
        local DEFAULT_TALKER_OFFSET = Vector3(0, -400, 0)
        if inst:HasTag("npc_ghost") then
            return TALLER_TALKER_OFFSET
        else
            return DEFAULT_TALKER_OFFSET
        end
        -- local rider = inst.replica.rider
        -- return (rider ~= nil and rider:IsRiding() or inst:HasTag("playerghost"))
        --     and TALLER_TALKER_OFFSET
        --     or DEFAULT_TALKER_OFFSET
    end
    inst.components.talker:SetOffsetFn(GetTalkerOffset)
    ---------------------------------------------------------------------------------------------
    inst.entity:SetPristine()


    inst.soundsname = "wilson"

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("locomotor") -- locomotor must be constructed before the stategraph

    inst:AddComponent("hunger")
    inst.components.hunger:Pause()

    inst:AddComponent("health")
    inst.components.health:SetMaxHealth(5000)

    inst:AddComponent("sanity")
    inst.components.sanity:SetMax(5000)
    inst.components.sanity.ignore = true

    inst:AddComponent("temperature")
    inst.components.temperature:SetTemp(TUNING.STARTING_TEMP)
    -- inst:AddComponent("combat")

    inst:AddComponent("inventory") --- 物品栏

    inst:AddComponent("trader")
    -- inst.components.trader:SetAcceptTest(ShouldAcceptItem)
    -- inst.components.trader.onaccept = OnGetItem
    -- inst.components.trader.deleteitemonaccept = false

    inst:AddComponent("debuffable")
    inst.components.debuffable:SetFollowSymbol("headbase", 0, -200, 0)

    inst:AddComponent("rider")


    inst:AddComponent("npc_base_lib")
    inst.npc_base_lib = inst.components.npc_base_lib
    -------------------------------------------------------------------------------------------------------
    ---- SGwilson.lua 里必须用到的 func
    inst.GetStormLevel = function() return 0 end
    inst.IsCarefulWalking = function() return false  end
    inst.IsActing = function(self)
        return self.sg:HasStateTag("acting") or (self._is_onstage_task ~= nil)
    end
    -------------------------------------------------------------------------------------------------------



    inst:ListenForEvent("player_link",function(inst,tar_player)
        inst.__link_player = tar_player
        if tar_player and tar_player:HasTag("player") then
            tar_player.__link_npc = inst
        end
    end)

    inst:ListenForEvent("player_unlink",function()
        if inst.__link_player then
            inst.__link_player.__link_npc = nil
        end
    end)

    inst:DoTaskInTime(0.1,function()
        if inst.__link_player == nil then
            inst:Remove()
            print("warning : npc.__link_player == nil , inst:Remove() ")
        else
            print("npc create and  link succeed")
        end
    end)

    function inst:GetPlayer()
        return self.__link_player
    end

    inst:SetStateGraph("SGwilson")

    return inst
end
 
return Prefab("wilson_npc", fn, assets)
